<template>
  <div class="content-topbar">
    <div class="content-inner">
      <div>
        <img src="../../assets/images/ContentImgs/logo.png" alt="logo" class="content-logo">
        <span class="version"><span>V</span> {{ packageData.version }}</span>
      </div>
      <div class="content-inner-tabs">
        <!-- 网盘 -->
        <div :class="curRouteCnt === '网盘' ? 'tabs active' : 'tabs'" @click="tabsClick('网盘')">
          网盘<div :class="curRouteCnt === '网盘' ? 'tabs-bottom' : ''"></div>
        </div>
        <!-- 分享 -->
        <div :class="curRouteCnt === '分享' ? 'tabs active' : 'tabs'" @click="tabsClick('分享')">
          分享<div :class="curRouteCnt === '分享' ? 'tabs-bottom' : ''"></div>
        </div>
        <!-- 一刻相册 -->
        <div :class="curRouteCnt === '一刻相册' ? 'tabs active' : 'tabs'" @click="tabsClick('一刻相册')">
          一刻相册<div :class="curRouteCnt === '一刻相册' ? 'tabs-bottom' : ''"></div>
        </div>
        <!-- 更多 -->
        <div class="tabs" @click="tabsClick('更多')">更多  <span class="el-icon-caret-bottom"></span></div>
        <!-- 用户信息 -->
        <div class="user-info" @mouseenter="userInfoDialogVisible = true" @mouseleave="userInfoDialogVisible = false">
          <el-avatar style="vertical-align: middle;" size="small">
            {{ $store.state.userInfo.name.substr(0, 1).toUpperCase() }}
          </el-avatar>
          <span class="phone">{{ secretPhone($store.state.userInfo.phone) }}</span>
          <i class="el-icon-arrow-down" style="font-weight: 900;cursor: pointer;margin-left: 6px;"></i>
          <!-- 弹出框 -->
          <div class="user-info-dialog" v-show="userInfoDialogVisible">
            <div class="user-info-dialog-top">
              <el-avatar style="vertical-align: middle;margin-top: 3px;" :size="45">
                {{ $store.state.userInfo.name.substr(0, 1).toUpperCase() }}
              </el-avatar>
              <span class="phone" style="color: #fff;">{{ secretPhone($store.state.userInfo.phone) }}</span>
            </div>
            <div v-for="(item, i) in userInfoList" :key="i" class="user-info-dialog-item" @click="tabsClick(item)">{{ item }}</div>
          </div>
        </div>
        <!-- 竖线 -->
        <div class="tabs-right-bar"></div>
        <!-- 客户端下载 -->
        <div class="tabs-useless" @click="tabsClick('客户端下载')">客户端下载</div>
        <!-- 右侧三个无功能图标 -->
        <i class="el-icon-bell useless-icon" @click="tabsClick('通知')"></i>
        <i class="el-icon-tickets useless-icon" @click="tabsClick('意见反馈')"></i>
        <i class="el-icon-goods useless-icon" @click="tabsClick('皮肤')"></i>
        <!-- 开通超级会员 -->
        <div class="content-vip-button" @click="tabsClick('开通超级会员')">开通超级会员</div>
        <!-- 前往新版 -->
        <div class="content-to-new-button" @click="tabsClick('前往新版')">前往新版</div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
const packageData = require('../../../package.json');

export default {
  name: 'ContentTopbar',
  computed: {
    ...mapState(['curRouteCnt'])
  },
  data() {
    return {
      userInfoDialogVisible: false,
      userInfoList: ['设备管理', '个人资料', '设置二级密码', '企业认证', '帮助中心', '退出'],
      packageData: packageData
    }
  },
  methods: {
    tabsClick(context) {
      switch(context) {
        case '网盘':
          this.$emit('changeRoute', ['/content/pan/all-files', '网盘']);
          this.$store.commit('setCurCntLeftRoute', '全部文件');
          this.$store.commit('setInitContentRoute', context);
          break;
        case '分享':
          this.$emit('changeRoute', ['/content/share', '分享']);
          this.$store.commit('setInitContentRoute', context);
          break;
        case '更多':
          this.$message.warning('没有更多，只有这么多');
          break;
        case '退出':
          this.$router.replace('/home');
          break;
        case '客户端下载':
          window.location.href="https://pan.baidu.com/download";
          break;
        case '开通超级会员':
          this.$message.warning('不用开通，你就是我的超级会员（づ￣3￣）づ╭❤～');
          break;
        case '前往新版': 
          this.$message.warning('当前版本就是最新版，做人不能太贪(～￣(OO)￣)ブ');
          break;
        default:
          this.$message.warning('该功能暂未开放，敬请期待...');
      }
    },
    secretPhone(val) {
      let front = val.toString().substr(0, 3);
      let behind = val.toString().substr(7, 10);
      return `${front}****${behind}`;
    },
  }
}
</script>

<style lang="less">
.content-topbar {
  height: 62px;
  width: 100%;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  background-color: #ffffff;
  box-sizing: border-box;
  padding-top: 11px;

  .content-inner {
    padding: 0 20px;
    height: 40px;
    display: flex;
    justify-content: space-between;

    .content-logo {
      height: 32px;
      margin-top: 4px;
    }

    .version {
      font-size: 12px;
      color: #666666;
      margin-left: 8px;
      vertical-align: super;

      span {
        font-size: 14px;
      }
    }

    .tabs {
      font-size: 16px;
      color: #333333;
      line-height: 40px;
      cursor: pointer;
      position: relative;
      display: inline-block;
      margin: 0 20px;

      &.active {
        color: #09aaff;
      }

      .tabs-bottom {
        width: 20px;
        height: 3px;
        background-color: #09aaff;
        position: absolute;
        left: 50%;
        transform: translate(-50%);
        border-radius: 2px;
      }
    }

    .tabs-right-bar {
      display: inline-block;
      height: 12px;
      width: .5px;
      background-color: #666;
      margin: 0 10px 0;
    }

    .tabs-useless {
      font-size: 12px;
      color: #333333;
      display: inline-block;
      margin-right: 18px;
      cursor: pointer;
      &:hover {
        opacity: .8;
      }
    }

    .useless-icon {
      font-size: 16px;
      font-weight: bold;
      margin-right: 18px;
      color: #7c878e;
      cursor: pointer;
    }

    .user-info {
      display: inline-block;
      line-height: 40px;

      .phone {
        font-size: 13px;
        color: #434e67;
        margin-left: 10px;
      }

      .user-info-dialog {
        width: 260px;
        height: 300px;
        border-radius: 5px;
        position: absolute;
        background-color: #ffffff;
        box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
        z-index: 10;

        .user-info-dialog-top {
          height: 90px;
          box-sizing: border-box;
          padding: 20px 15px;
          background: url('../../assets/images/ContentImgs/user-info-bg.png');
          border-top-left-radius: 5px;
          border-top-right-radius: 5px;
        }

        .user-info-dialog-item {
          width: 100%;
          height: 35px;
          font-size: 12px;
          color: #333333;
          padding-left: 12px;
          line-height: 35px;
          box-sizing: border-box;
          cursor: pointer;
          &:hover {
            background-color: #f0f8fd;
          }
        }
      }
    }
  }

  .content-vip-button {
    width: 102px;
    height: 23.6px;
    background: linear-gradient(-139deg,#f0d7a3 0,#efcb85 100%) #f0d7a3;
    text-align: center;
    line-height: 23.6px;
    border-radius: 20px;
    box-sizing: border-box;
    margin-right: 10px;
    font-size: 12px;
    display: inline-block;
    cursor: pointer;
    &:hover {
      background: #e7c062;
    }
  }

  .content-to-new-button {
    width: 80px;
    height: 27px;
    line-height: 27px;
    background-color: #06a7ff;
    border-radius: 16px;
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    display: inline-block;
    text-align: center;
    cursor: pointer;
    &:hover {
      background-color: #009aef;
    }
  }

  .el-avatar {
    background: #0a99ff;
  }
}
</style>